/**
* Copyright (c) By zengqh.
*
* This program is just for fun or demo, in the hope that it  
* will be useful, you can redistribute it and/or modify freely.
*
* Time: 2012/08/31
* File: CubeUiAniSceneNode.cpp
* Blog: http://www.cnblogs.com/zengqh/
**/

#include "CubeUiAniSceneNode.h"

CubeUiAniSceneNode::CubeUiAniSceneNode(
									   SceneManager* scene_mgr, 
									   s32 id /* = -1 */, 
									   s32 type /* = 0 */)
									   : AnimationSceneNode(scene_mgr, id, type)
{

}

CubeUiAniSceneNode::~CubeUiAniSceneNode()
{

}

void CubeUiAniSceneNode::render()
{

}

void CubeUiAniSceneNode::onAnimation(f32 time)
{
	if (!_anim)
	{
		return;
	}

	if (_is_anim_start)
	{

		if (_need_update_first_time)
		{
			_start_anim_time = GetTickCount();
			_need_update_first_time = false;
		}

		_curr_anim_time = GetTickCount();

	}

	AniKeyFrame* kf = _anim->getInterpolatedKeyFrame(_curr_anim_time - _start_anim_time);
}

void CubeUiAniSceneNode::setupContent()
{
	setupCube();

	
}

void CubeUiAniSceneNode::setupCube()
{
	/* setup vertex */
	RenderSystem* render_system = _scene_mgr->getRenderSystem();

	_vbo_buffer = render_system->createGraphicsBuffer(BU_Static, BA_Read_Write, BS_VERTEX_BUFFER);

	_vbo_buffer->resize(sizeof(cube_vertex_content));
	GraphicsBuffer::Mapper vbo_mapper(*_vbo_buffer, BA_Write_Only);

	u8* vbo_raw_buffer = vbo_mapper.Pointer<u8>();
	memcpy(vbo_raw_buffer, data, _vbo_buffer->size());

	/* setup index */
	_idx_buffer = render_system->createGraphicsBuffer(BU_Static, BA_Read_Write, BS_INDEX_BUFFER);

	u32 size = sizeof(cube_index_content);

	_idx_buffer->resize(size);
	GraphicsBuffer::Mapper idx_mapper(*_idx_buffer, BA_Write_Only);

	u8* idx_raw_buffer = idx_mapper.Pointer<u8>();
	memcpy(idx_raw_buffer, data, _idx_buffer->size());
}